Imports Microsoft.VisualBasic
Imports System.Web.HttpContext
Imports Framework

Public Class CSitemap

    Public Shared MOBI_PATH As String = String.Concat(CConfig.DropboxPublic, "ebooks\latest.mobi")
    Public Shared EPUB_PATH As String = String.Concat(CConfig.DropboxPublic, "ebooks\latest.epub")
    Public Shared HTML_PATH As String = String.Concat(CConfig.DropboxPublic, "ebooks\latest.htm")

    Public Shared MOBI_URL As String = String.Concat(CConfig.DropboxUrl("ebooks\latest.mobi"))
    Public Shared EPUB_URL As String = String.Concat(CConfig.DropboxUrl("ebooks\latest.epub"))
    Public Shared HTML_URL As String = String.Concat(CConfig.DropboxUrl("ebooks\latest.htm"))

#Region "Public"
    Public Shared Function Home() As String
        Return "~/"
    End Function

    'Friendly-Urls
    Public Shared Function Sermons() As String
        Return "~/sermons.aspx"
    End Function
    Public Shared Function ConferenceSets() As String
        Return "~/conference_sets.aspx"
    End Function
    Public Shared Function Paperbacks() As String
        Return "~/paperbacks.aspx"
    End Function
    Public Shared Function Manuals() As String
        Return "~/manuals.aspx"
    End Function
    Public Shared Function Ebooks() As String
        Return "~/ebooks.aspx"
    End Function
    Public Shared Function Transcripts() As String
        Return "~/transcripts.aspx"
    End Function
    Public Shared Function Chinese() As String
        Return "~/chinese.aspx"
    End Function
    Public Shared Function Audio() As String
        Return "~/audio.aspx"
    End Function
    Public Shared Function Video() As String
        Return "~/video.aspx"
    End Function
    Public Shared Function Notes() As String
        Return "~/notes.aspx"
    End Function

    Public Shared Function Sermons(search As String, speakerId As Integer) As String
        Return Sermons(search, speakerId, 0)
    End Function
    Public Shared Function ConferenceSets(search As String, speakerId As Integer) As String
        Return ConferenceSets(search, speakerId, 0)
    End Function
    Public Shared Function Audio(search As String, speakerId As Integer) As String
        Return Audio(search, speakerId, 0)
    End Function
    Public Shared Function Video(search As String, speakerId As Integer) As String
        Return Video(search, speakerId, 0)
    End Function
    Public Shared Function Sermons(search As String, speakerId As Integer, languageId As Integer) As String
        Return AddParams(CSitemap.Sermons, search, speakerId, languageId)
    End Function
    Public Shared Function ConferenceSets(search As String, speakerId As Integer, languageId As Integer) As String
        Return AddParams(CSitemap.ConferenceSets, search, speakerId, languageId)
    End Function
    Public Shared Function Paperbacks(search As String, speakerId As Integer) As String
        Return AddParams(CSitemap.Paperbacks, search, speakerId)
    End Function
    Public Shared Function Manuals(search As String, speakerId As Integer) As String
        Return AddParams(CSitemap.Manuals, search, speakerId)
    End Function
    Public Shared Function Ebooks(search As String, speakerId As Integer) As String
        Return AddParams(CSitemap.Ebooks, search, speakerId)
    End Function
    Public Shared Function Transcripts(search As String, speakerId As Integer) As String
        Return AddParams(CSitemap.Transcripts, search, speakerId)
    End Function
    Public Shared Function Chinese(search As String, speakerId As Integer) As String
        Return AddParams(CSitemap.Chinese, search, speakerId)
    End Function
    Public Shared Function Audio(search As String, speakerId As Integer, languageId As Integer) As String
        Return AddParams(CSitemap.Audio, search, speakerId, languageId)
    End Function
    Public Shared Function Video(search As String, speakerId As Integer, languageId As Integer) As String
        Return AddParams(CSitemap.Video, search, speakerId, languageId)
    End Function
    Public Shared Function Notes(search As String, speakerId As Integer) As String
        Return AddParams(CSitemap.Notes, search, speakerId)
    End Function


    Public Shared Function Sermons_(search As String, speakerId As Integer, languageId As Integer) As String
        Return AbsUrl(Sermons(search, speakerId, languageId))
    End Function
    Public Shared Function ConferenceSets_(search As String, speakerId As Integer, languageId As Integer) As String
        Return AbsUrl(ConferenceSets(search, speakerId, languageId))
    End Function
    Public Shared Function Paperbacks_(search As String, speakerId As Integer) As String
        Return AbsUrl(Paperbacks(search, speakerId))
    End Function
    Public Shared Function Manuals_(search As String, speakerId As Integer) As String
        Return AbsUrl(Manuals(search, speakerId))
    End Function
    Public Shared Function Ebooks_(search As String, speakerId As Integer) As String
        Return AbsUrl(Ebooks(search, speakerId))
    End Function
    Public Shared Function Transcripts_(search As String, speakerId As Integer) As String
        Return AbsUrl(Transcripts(search, speakerId))
    End Function
    Public Shared Function Chinese_(search As String, speakerId As Integer) As String
        Return AbsUrl(Chinese(search, speakerId))
    End Function
    Public Shared Function Video_(search As String, speakerId As Integer) As String
        Return AbsUrl(Video(search, speakerId))
    End Function
    Public Shared Function Notes_(search As String, speakerId As Integer) As String
        Return AbsUrl(Notes(search, speakerId))
    End Function
    Public Shared Function Audio_(search As String, speakerId As Integer) As String
        Return AbsUrl(Audio(search, speakerId))
    End Function
    Private Shared Function AbsUrl(s As String) As String
        'If HttpContext.Current.Server.MachineName.ToLower.Contains("user-pc") Then Return "http://localhost:53763/Website" & s.Substring(1)
        Return String.Concat("http://mikeconnellministries.com", s.Substring(1))
    End Function

    'Ebooks
    Private Shared Function AddParams(url As String, search As String, speakerId As Integer) As String
        Return AddParams(url, search, speakerId, 0)
    End Function
    Private Shared Function AddParams(url As String, search As String, speakerId As Integer, languageId As Integer) As String
        Dim sb As New StringBuilder()
        If speakerId > 0 Then sb.Append("?speak=").Append(speakerId)
        If Not String.IsNullOrEmpty(search) Then
            If sb.Length > 0 Then sb.Append("&") Else sb.Append("?")
            sb.Append("search=").Append(Encode(search))
        End If
        If languageId > 0 Then
            If sb.Length > 0 Then sb.Append("&") Else sb.Append("?")
            sb.Append("lang=").Append(languageId)
        End If
        sb.Insert(0, url)
        Return sb.ToString
    End Function



    'Store
    Public Shared Function Store() As String
        Return ConferenceSets()
    End Function
    Public Shared Function Store(typeId As EProductType) As String
        Select Case typeId
            Case EProductType.Manual : Return Manuals()
            Case EProductType.Sermon : Return Sermons()
            Case EProductType.ConferenceSet : Return ConferenceSets()
            Case EProductType.Paperback : Return Paperbacks()
        End Select
        Return Sermons()
    End Function
    Public Shared Function StoreForSpeaker(speakerId As Byte) As String
        Return Sermons(Nothing, speakerId, 0)
    End Function




    'Product
    Public Shared Function Decide_(p As CProduct) As String
        Return AbsUrl(Decide(p))
    End Function
    Public Shared Function Decide(p As CProduct) As String
        'Return String.Concat("~/store/decide.aspx?productId=", p.ProductId, "&name=", Encode(p.ProductName.Replace(" ", "_")))
        Return String.Concat("~/", CConfig.ProductUrl(p))
    End Function


    'Free or Purchased Product
    Public Shared Function Download(o As COrder) As String
        Return String.Concat("~/store/download.aspx?orderId=", o.OrderId, "&security=", Encode(o.Customer.CustomerEmail))
    End Function

    Public Shared Function Transcript(p As CProduct, Optional html As Boolean = True) As String
        Return Transcript(p.ProductId, html)
    End Function
    Public Shared Function Transcript(productId As Integer, Optional html As Boolean = True) As String
        Return String.Concat("~/transcript.aspx?productId=", productId, IIf(html, String.Empty, "&html=false"))
    End Function

    Public Shared Function TranscriptWithPaging(p As CProduct) As String
        Return String.Concat("~/transcript/", p.ProductId, "/", CConfig.SafeFriendlyName(p.ProductName), ".aspx")
    End Function
    Public Shared Function TranscriptWithPaging(p As CProduct, page As Integer) As String
        Return String.Concat(TranscriptWithPaging(p), "?p=", page)
    End Function
    Public Shared Function TranscriptWithPaging_(p As CProduct) As String
        Return AbsUrl(TranscriptWithPaging(p))
    End Function
    Public Shared Function TranscriptWithPaging_(p As CProduct, page As Integer) As String
        Return AbsUrl(TranscriptWithPaging(p, page))
    End Function

    Public Shared Function TranscriptChineseSimplified(p As CProduct) As String
        Return String.Concat("~/chinese_simplified/", p.ProductId, "/", CConfig.SafeFriendlyName(p.ProductNameChineseSimplified), ".aspx")
    End Function
    Public Shared Function TranscriptChineseSimplified(p As CProduct, page As Integer) As String
        Return String.Concat(TranscriptChineseSimplified(p), "?p=", page)
    End Function
    Public Shared Function TranscriptChineseSimplified_(p As CProduct) As String
        Return AbsUrl(TranscriptChineseSimplified(p))
    End Function
    Public Shared Function TranscriptChineseSimplified_(p As CProduct, page As Integer) As String
        Return AbsUrl(TranscriptChineseSimplified(p, page))
    End Function

    Public Shared Function TranscriptChineseTraditional(p As CProduct) As String
        Return String.Concat("~/chinese_traditional/", p.ProductId, "/", CConfig.SafeFriendlyName(p.ProductNameChineseTraditionalOrSimplified), "_.aspx") 'underscore is for caching, in case names are the same
    End Function
    Public Shared Function TranscriptChineseTraditional(p As CProduct, page As Integer) As String
        Return String.Concat(TranscriptChineseTraditional(p), "?p=", page)
    End Function
    Public Shared Function TranscriptChineseTraditional_(p As CProduct) As String
        Return AbsUrl(TranscriptChineseTraditional(p))
    End Function
    Public Shared Function TranscriptChineseTraditional_(p As CProduct, page As Integer) As String
        Return AbsUrl(TranscriptChineseTraditional(p, page))
    End Function

    'About Page
    Public Shared Function About() As String
        Return "~/about.aspx"
        'Return "~/about"
    End Function

    'Schedule Page
    Public Shared Function Schedule() As String
        Return "~/schedule.aspx"
        'Return "~/schedule"
    End Function

    'Schedule Page
    Public Shared Function Photos() As String
        Return "~/youtube.aspx"
        'Return "~/Photos.aspx"
    End Function

    'External
    'Ping: https://phobos.apple.com/WebObjects/MZFinance.woa/wa/pingPodcast?id=523085771
    Public Shared Function External_Podcast() As String
        Return CConfig.External_Podcast
    End Function
    Public Shared Function External_Facebook() As String
        Return CConfig.External_Facebook
    End Function
    Public Shared Function External_FacebookLike(p As CProduct) As String
        Return CConfig.External_FacebookLike(p)
    End Function
    Public Shared Function External_FacebookShare(p As CProduct) As String
        Return CConfig.External_FacebookShare(p)
    End Function


    Public Shared Function External_Twitter() As String
        Return CConfig.External_Twitter
    End Function
    Public Shared Function External_Donations() As String
        Return CConfig.External_Donations
    End Function
    Public Shared Function External_DonationsJeremy() As String
        Return CConfig.External_DonationsJeremy
    End Function
    Public Shared Function External_Paypal(buttonCode As String) As String
        Return CConfig.External_Paypal(buttonCode)
    End Function
    Public Shared Function External_Review(p As CProduct) As String
        Return External_Review(p.ProductSmashwordsId, p.ProductAmazonId)
    End Function
    Public Shared Function External_Review(smashwordsId As Integer, amazonId As String) As String
        If String.IsNullOrEmpty(amazonId) Then
            If smashwordsId > 0 Then
                Return External_ReviewSmashwords(smashwordsId)
            Else
                Return CConfig.External_Amazon
            End If
        End If
        Return External_ReviewAmazon(amazonId)
    End Function
    Public Shared Function External_ReviewAmazon(p As CProduct) As String
        If Not String.IsNullOrEmpty(p.ProductAmazonId) Then
            Return External_ReviewAmazon(p.ProductAmazonId)
        ElseIf p.HasParent Then
            Return External_ReviewAmazon(p.BelongsTo)
        End If
        Return External_Amazon()
    End Function
    Public Shared Function External_ReviewSmashwords(p As CProduct) As String
        If p.ProductSmashwordsId > 0 Then
            Return External_ReviewSmashwords(p.ProductSmashwordsId)
        ElseIf p.HasParent Then
            Return External_ReviewSmashwords(p.BelongsTo)
        End If
        Return External_Smashwords()
    End Function
    Public Shared Function External_ReviewAmazon(amazonId As String) As String
        Return CConfig.External_Amazon(amazonId) & "#customerreviews"
    End Function
    Public Shared Function External_ReviewSmashwords(smashwordsId As Integer) As String
        Return CConfig.External_Review(smashwordsId)
    End Function

    Public Shared Function External_Smashwords(id As Integer) As String
        Return CConfig.External_Smashwords(id)
    End Function
    Public Shared Function External_Smashwords() As String
        Return CConfig.External_Smashwords
    End Function
    Public Shared Function External_Amazon(id As String) As String
        Return External_Amazon(id, String.Empty) 'name not used anymore
    End Function
    Public Shared Function External_Amazon(id As String, name As String) As String
        Return CConfig.External_Amazon(id, name)
    End Function
    Public Shared Function External_Amazon() As String
        Return CConfig.External_Amazon
    End Function
    Public Shared Function External_Vimeo() As String
        Return CConfig.External_Vimeo
    End Function
    Public Shared Function External_YouTube() As String
        Return CConfig.External_YouTube
    End Function
    Public Shared Function External_CreateSpace(id As Integer) As String
        Return CConfig.External_CreateSpace(id)
    End Function
    Public Shared Function External_CreateSpace(p As CProduct) As String
        Return CConfig.External_CreateSpace(p.ProductCSBookId)
    End Function

    'UserControls



    Public Shared Function Store_UCManual() As String
        Return "~/store/UCManual.ascx"
    End Function
    Public Shared Function Store_UCArt() As String
        Return "~/store/UCArt.ascx"
    End Function
    Public Shared Function Store_UCNotes() As String
        Return "~/store/UCNotes.ascx"
    End Function
    Public Shared Function Store_UCVideo() As String
        Return "~/store/UCVideo.ascx"
    End Function
    Public Shared Function Store_UCAudio() As String
        Return "~/store/UCAudio.ascx"
    End Function
    Public Shared Function Store_UCTranscript() As String
        Return "~/store/UCTranscript.ascx"
    End Function
    Public Shared Function Store_UCEBook() As String
        Return "~/store/UCEBook.ascx"
    End Function
    Public Shared Function Store_UCSet() As String
        Return "~/store/UCSet.ascx"
    End Function
    Public Shared Function Store_UCSermon() As String
        Return "~/store/UCSermon.ascx"
    End Function
    Public Shared Function Store_UCSermon2() As String
        Return "~/store/UCSermon2.ascx"
    End Function
    Public Shared Function Store_UCCreatespace() As String
        Return "~/store/UCCreatespace.ascx"
    End Function
    Public Shared Function Store_UCContent() As String
        Return "~/store/UCContent.ascx"
    End Function
    Public Shared Function Store_UCDownload() As String
        Return "~/store/UCDownload.ascx"
    End Function
#End Region

#Region "Speakers"
    'List/Search
    Public Shared Function [Speakers]() As String
        Return "~/pages/speakers/default.aspx"
    End Function
    Public Shared Function [Speakers](ByVal search As String) As String
        Return String.Concat(CSitemap.Speakers(), "?search=", Encode(search))
    End Function
    Public Shared Function [Speakers](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Speakers(search), "&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1)
    End Function

    'Add/Edit
    Private Shared Function SpeakerAddEdit() As String
        Return "~/pages/speakers/speaker.aspx"
    End Function
    Public Shared Function SpeakerAdd() As String 'May require a parentId (follow pattern below)
        Return SpeakerAddEdit()
    End Function
    Public Shared Function SpeakerEdit(ByVal speakerId As Byte) As String
        Return String.Concat(SpeakerAddEdit, "?speakerId=", speakerId)
    End Function

    'UserControls
    Public Shared Function UCSpeaker() As String
        Return "~/pages//speakers/usercontrols/UCSpeaker.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function SpeakerUploads(Optional relative As Boolean = True) As String
        If relative Then Return "~/uploads/speakers/"
        Return String.Concat(CConfig.DropboxLiveData, SpeakerUploads(True).Substring(2))
    End Function
#End Region

#Region "Locations"
    'List/Search
    Public Shared Function [Locations]() As String
        Return "~/pages/locations/default.aspx"
    End Function
    Public Shared Function [Locations](ByVal search As String) As String
        Return String.Concat(CSitemap.Locations(), "?search=", Encode(search))
    End Function
    Public Shared Function [Locations](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Locations(search), "&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1)
    End Function

    'Add/Edit
    Private Shared Function LocationAddEdit() As String
        Return "~/pages/locations/location.aspx"
    End Function
    Public Shared Function LocationAdd() As String 'May require a parentId (follow pattern below)
        Return LocationAddEdit()
    End Function
    Public Shared Function LocationEdit(ByVal locationId As Byte) As String
        Return String.Concat(LocationAddEdit, "?locationId=", locationId)
    End Function

    'UserControls
    Public Shared Function UCLocation() As String
        Return "~/pages//locations/usercontrols/UCLocation.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function LocationUploads() As String
        Return "~/uploads/locations/"
    End Function
#End Region

#Region "Scribes"
    'List/Search
    Public Shared Function [Scribes]() As String
        Return "~/pages/scribes/default.aspx"
    End Function
    Public Shared Function [Scribes](ByVal search As String) As String
        Return String.Concat(CSitemap.Scribes(), "?search=", Encode(search))
    End Function
    Public Shared Function [Scribes](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Scribes(search), "&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1)
    End Function

    'Add/Edit
    Private Shared Function ScribeAddEdit() As String
        Return "~/pages/scribes/scribe.aspx"
    End Function
    Public Shared Function ScribeAdd() As String 'May require a parentId (follow pattern below)
        Return ScribeAddEdit()
    End Function
    Public Shared Function ScribeEdit(ByVal scribeId As Byte) As String
        Return String.Concat(ScribeAddEdit, "?scribeId=", scribeId)
    End Function

    'UserControls
    Public Shared Function UCScribe() As String
        Return "~/pages//scribes/usercontrols/UCScribe.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function ScribeUploads() As String
        Return "~/uploads/scribes/"
    End Function
#End Region


#Region "Buttons"
    'List/Search
    Public Shared Function [Buttons]() As String
        Return "~/pages/buttons/default.aspx"
    End Function
    Public Shared Function [Buttons](ByVal search As String) As String
        Return String.Concat(CSitemap.Buttons(), "?search=", Encode(search))
    End Function
    Public Shared Function [Buttons](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Buttons(search), Paging(pi))
    End Function

    'Add/Edit
    Private Shared Function ButtonAddEdit() As String
        Return "~/pages/buttons/button.aspx"
    End Function
    Public Shared Function ButtonAdd() As String 'May require a parentId (follow pattern below)
        Return ButtonAddEdit()
    End Function
    Public Shared Function ButtonEdit(ByVal buttonId As Integer) As String
        Return String.Concat(ButtonAddEdit, "?buttonId=", buttonId)
    End Function

    'UserControls
    Public Shared Function UCButton() As String
        Return "~/pages//buttons/usercontrols/UCButton.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function ButtonUploads() As String
        Return "~/uploads/buttons/"
    End Function
#End Region

#Region "Settings"
    'List/Search
    Public Shared Function [Settings]() As String
        Return "~/pages/settings/default.aspx"
    End Function
    Public Shared Function [Settings](ByVal search As String) As String
        Return String.Concat(CSitemap.Settings(), "?search=", Encode(search))
    End Function
    Public Shared Function [Settings](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Settings(search), Paging(pi))
    End Function

    'Add/Edit
    Private Shared Function SettingAddEdit() As String
        Return "~/pages/settings/setting.aspx"
    End Function
    Public Shared Function SettingAdd() As String 'May require a parentId (follow pattern below)
        Return SettingAddEdit()
    End Function
    Public Shared Function SettingEdit(ByVal settingId As Integer) As String
        Return String.Concat(SettingAddEdit, "?settingId=", settingId)
    End Function
    Public Shared Function SettingValue(ByVal settingId As Integer) As String
        Return String.Concat("~/pages/settings/settingValue.aspx?settingId=", settingId)
    End Function

    'UserControls
    Public Shared Function UCSetting() As String
        Return "~/pages//settings/usercontrols/UCSetting.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function SettingUploads(Optional relative As Boolean = True) As String
        If relative Then Return "~/uploads/settings/"
        Return String.Concat(CConfig.DropboxLiveData, SettingUploads(True).Substring(2))
    End Function
#End Region



#Region "Languages"
    'List/Search
    Public Shared Function [Languages]() As String
        Return "~/pages/languages/default.aspx"
    End Function
    Public Shared Function [Languages](ByVal search As String) As String
        Return String.Concat(CSitemap.Languages(), "?search=", Encode(search))
    End Function
    Public Shared Function [Languages](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Languages(search), Paging(pi))
    End Function

    'Add/Edit
    Private Shared Function LanguageAddEdit() As String
        Return "~/pages/languages/language.aspx"
    End Function
    Public Shared Function LanguageAdd() As String 'May require a parentId (follow pattern below)
        Return LanguageAddEdit()
    End Function
    Public Shared Function LanguageEdit(ByVal languageId As Byte) As String
        Return String.Concat(LanguageAddEdit, "?languageId=", languageId)
    End Function

    'UserControls
    Public Shared Function UCLanguage() As String
        Return "~/pages//languages/usercontrols/UCLanguage.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function LanguageUploads() As String
        Return "~/uploads/languages/"
    End Function
#End Region


#Region "EmailTemplates"
    'List/Search
    Public Shared Function [EmailTemplates]() As String
        Return "~/pages/emailTemplates/default.aspx"
    End Function
    Public Shared Function [EmailTemplates](ByVal search As String, showComponents As Boolean) As String
        Return String.Concat(CSitemap.EmailTemplates(), "?search=", Encode(search), "&showComponents=", showComponents)
    End Function
    Public Shared Function [EmailTemplates](ByVal search As String, showComponents As Boolean, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.EmailTemplates(search, showComponents), Paging(pi))
    End Function

    'Add/Edit
    Private Shared Function EmailTemplateAddEdit() As String
        Return "~/pages/emailTemplates/emailTemplate.aspx"
    End Function
    Public Shared Function EmailTemplateAdd() As String 'May require a parentId (follow pattern below)
        Return EmailTemplateAddEdit()
    End Function
    Public Shared Function EmailTemplateEdit(ByVal templateId As Integer) As String
        Return String.Concat(EmailTemplateAddEdit, "?templateId=", templateId)
    End Function
    Public Shared Function EmailTemplatePreview(ByVal templateId As Integer) As String
        Return String.Concat("~/pages/emailTemplates/preview.aspx?templateId=", templateId)
    End Function

    'UserControls
    Public Shared Function UCEmailTemplate() As String
        Return "~/pages//emailTemplates/usercontrols/UCEmailTemplate.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function EmailTemplateUploads() As String
        Return "~/uploads/emailTemplates/"
    End Function
#End Region


#Region "Files"
    'List/Search
    Public Shared Function [Files]() As String
        Return "~/pages/files/default.aspx"
    End Function
    Public Shared Function [Files](ByVal search As String, extensionId As Integer) As String
        Return String.Concat(CSitemap.Files(), "?search=", Encode(search), "&extensionId=", Str(extensionId))
    End Function
    Public Shared Function [Files](ByVal search As String, extensionId As Byte?, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Files(search, extensionId), Paging(pi))
    End Function

    Public Shared Function FilesMissing() As String
        Return "~/pages/files/missing.aspx"
    End Function
    Public Shared Function FilesMissing(extensionId As Integer) As String
        Return String.Concat(CSitemap.FilesMissing(), "?extensionId=", Str(extensionId))
    End Function
    Public Shared Function FilesMissing(extensionId As Byte?, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.FilesMissing(extensionId), Paging(pi))
    End Function

    Public Shared Function Duplicates() As String
        Return "~/pages/files/duplicates.aspx"
    End Function

    'Add/Edit
    Private Shared Function FileAddEdit() As String
        Return "~/pages/files/file.aspx"
    End Function
    Public Shared Function FileAdd() As String 'May require a parentId (follow pattern below)
        Return FileAddEdit()
    End Function
    Public Shared Function FileEdit(ByVal fileId As Integer) As String
        Return String.Concat(FileAddEdit, "?fileId=", fileId)
    End Function

    'UserControls
    Public Shared Function UCFile() As String
        Return "~/pages//files/usercontrols/UCFile.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function FileUploads() As String
        Return "~/uploads/files/"
    End Function
#End Region


#Region "Customers"
    'List/Search
    Public Shared Function [Customers]() As String
        Return "~/pages/customers/default.aspx"
    End Function
    Public Shared Function [Customers](ByVal search As String, paying As Boolean) As String
        Return String.Concat(CSitemap.Customers(), "?search=", Encode(search), "&paying=", paying)
    End Function
    Public Shared Function [Customers](ByVal search As String, paying As Boolean, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Customers(search, paying), Paging(pi))
    End Function

    'UserControls
    Public Shared Function UCCustomer() As String
        Return "~/pages//customers/usercontrols/UCCustomer.ascx"
    End Function

    'View Details
    Public Shared Function [Customer](ByVal customerId As Integer) As String
        Return String.Concat("~/pages/customers/customer.aspx?customerId=", customerId)
    End Function
#End Region

#Region "Payments"
    'List/Search
    Public Shared Function [Payments]() As String
        Return "~/pages/payments/default.aspx"
    End Function
    Public Shared Function [Payments](ByVal search As String, orderId As Integer, customerId As Integer, productId As Integer) As String
        Return String.Concat(CSitemap.Payments(), "?search=", Encode(search), "&orderId=", Str(orderId), "&customerId=", Str(customerId), "&productId=", Str(productId))
    End Function
    Public Shared Function [Payments](ByVal search As String, orderId As Integer, customerId As Integer, productId As Integer, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Payments(search, orderId, customerId, productId), Paging(pi))
    End Function
    Public Shared Function PaymentsForOrder(ByVal orderId As Integer) As String
        Return String.Concat(CSitemap.Payments(), "?orderId=", orderId)
    End Function
    Public Shared Function PaymentsForCustomer(ByVal customerId As Integer) As String
        Return String.Concat(CSitemap.Payments(), "?customerId=", customerId)
    End Function
    Public Shared Function PaymentsForProduct(ByVal productId As Integer) As String
        Return String.Concat(CSitemap.Payments(), "?productId=", productId)
    End Function

    'UserControls
    Public Shared Function UCPayment() As String
        Return "~/pages//payments/usercontrols/UCPayment.ascx"
    End Function

    'View Details
    Public Shared Function [Payment](ByVal paymentId As Integer) As String
        Return String.Concat("~/pages/payments/payment.aspx?paymentId=", paymentId)
    End Function
#End Region

#Region "Orders"
    'List/Search
    Public Shared Function [Orders]() As String
        Return "~/pages/orders/default.aspx"
    End Function
    Public Shared Function [Orders](ByVal search As String, productId As Integer, customerId As Integer, isPaid As Boolean?) As String
        Return String.Concat(CSitemap.Orders(), "?search=", Encode(search), "&productId=", Str(productId), "&customerId=", Str(customerId), "&isPaid=", Str(isPaid))
    End Function
    Public Shared Function [Orders](ByVal search As String, productId As Integer, customerId As Integer, isPaid As Boolean?, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Orders(search, productId, customerId, isPaid), Paging(pi))
    End Function
    Public Shared Function OrdersForCustomer(ByVal customerId As Integer) As String
        Return String.Concat(CSitemap.Orders(), "?customerId=", customerId)
    End Function
    Public Shared Function OrdersForProduct(ByVal productId As Integer) As String
        Return String.Concat(CSitemap.Orders(), "?productId=", productId)
    End Function

    'UserControls
    Public Shared Function UCOrder() As String
        Return "~/pages//orders/usercontrols/UCOrder.ascx"
    End Function

    'View Details
    Public Shared Function [Order](ByVal orderId As Integer) As String
        Return String.Concat("~/pages/orders/order.aspx?orderId=", orderId)
    End Function
#End Region

#Region "Products"
    'List/Search
    Public Shared Function [Products]() As String
        Return "~/pages/products/default.aspx"
    End Function
    Public Shared Function [Products](ByVal search As String, typeId As Integer, speakerId As Integer, scribeId As Integer, languageId As Integer, locationId As Integer, buttonId As Integer, isActive As Boolean?) As String
        Return String.Concat(CSitemap.Products(), "?search=", Encode(search), "&typeId=", Str(typeId), "&speakerId=", Str(speakerId), "&scribeId=", Str(scribeId), "&languageId=", Str(languageId), "&locationId=", Str(locationId), "&buttonId=", Str(buttonId), "&isActive=", Str(isActive))
    End Function
    Public Shared Function [Products](ByVal search As String, typeId As Integer, speakerId As Integer, scribeId As Integer, languageId As Integer, locationId As Integer, buttonId As Integer, isActive As Boolean?, showDetails As Boolean, showPictures As Boolean, showPricing As Boolean, showContents As Boolean, showTotals As Boolean) As String
        Return String.Concat(CSitemap.Products(search, typeId, speakerId, scribeId, languageId, locationId, buttonId, isActive), "&showDetails=", Str(showDetails), "&showPictures=", Str(showPictures), "&showPricing=", Str(showPricing), "&showContents=", Str(showContents), "&showTotals=", Str(showTotals))
    End Function
    Public Shared Function [Products](ByVal search As String, typeId As Integer, speakerId As Integer, scribeId As Integer, languageId As Integer, locationId As Integer, buttonId As Integer, isActive As Boolean?, showDetails As Boolean, showPictures As Boolean, showPricing As Boolean, showContents As Boolean, showTotals As Boolean, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Products(search, typeId, speakerId, scribeId, languageId, locationId, buttonId, isActive, showDetails, showPictures, showPricing, showContents, showTotals), Paging(pi))
    End Function
    Public Shared Function ProductsForSpeaker(speakerId As Byte) As String
        Return String.Concat(Products(Nothing, Integer.MinValue, speakerId, Integer.MinValue, Integer.MinValue, Integer.MinValue, Integer.MinValue, Nothing))
    End Function
    Public Shared Function ProductsForScribe(scribeId As Byte) As String
        Return String.Concat(Products(Nothing, Integer.MinValue, Integer.MinValue, scribeId, Integer.MinValue, Integer.MinValue, Integer.MinValue, Nothing))
    End Function
    Public Shared Function ProductsForLocation(locationId As Byte) As String
        Return String.Concat(Products(Nothing, Integer.MinValue, Integer.MinValue, Integer.MinValue, Integer.MinValue, locationId, Integer.MinValue, Nothing))
    End Function
    Public Shared Function ProductsForButton(buttonId As Integer) As String
        Return String.Concat(Products(Nothing, Integer.MinValue, Integer.MinValue, Integer.MinValue, Integer.MinValue, Integer.MinValue, buttonId, Nothing))
    End Function
    Public Shared Function ProductsForType(typeId As Integer) As String
        Return String.Concat(Products(Nothing, typeId, Integer.MinValue, Integer.MinValue, Integer.MinValue, Integer.MinValue, Integer.MinValue, Nothing))
    End Function


    'Add/Edit
    Private Shared Function ProductAdd() As String
        Return "~/pages/products/productAdd.aspx"
    End Function
    Private Shared Function ProductEdit() As String
        Return "~/pages/products/product.aspx"
    End Function
    Public Shared Function ProductAdd(typeId As Byte) As String 'May require a parentId (follow pattern below)
        Return String.Concat(CSitemap.ProductAdd, "?typeId=", typeId)
    End Function
    Public Shared Function ProductAdd(typeId As Byte, parentId As Integer) As String 'May require a parentId (follow pattern below)
        Return String.Concat(ProductAdd(typeId), "&belongsToId=", parentId)
    End Function
    Public Shared Function ProductEdit(ByVal productId As Integer) As String
        Return String.Concat(CSitemap.ProductEdit, "?productId=", productId)
    End Function

    Public Shared Function ProductImage(ByVal productId As Integer) As String
        Return String.Concat("~/pages/products/productimage.aspx?productId=", productId)
    End Function
    Public Shared Function ProductFiles(ByVal productId As Integer) As String
        Return String.Concat("~/pages/products/productfiles.aspx?productId=", productId)
    End Function
    Public Shared Function ProductTopics(ByVal productId As Integer) As String
        Return String.Concat("~/pages/products/producttopics.aspx?productId=", productId)
    End Function
    Public Shared Function ProductTranscription(ByVal productId As Integer) As String
        Return String.Concat("~/pages/products/producttranscript.aspx?productId=", productId)
    End Function
    Public Shared Function ProductVimeo(ByVal productId As Integer) As String
        Return String.Concat("~/pages/products/ProductVimeo.aspx?productId=", productId)
    End Function
    Public Shared Function ProductContents(ByVal productId As Integer) As String
        Return String.Concat("~/pages/products/ProductContents.aspx?productId=", productId)
    End Function


    'UserControls
    Public Shared Function UCProduct() As String
        Return "~/pages//products/usercontrols/UCProduct.ascx"
    End Function
    Public Shared Function UCSet() As String
        Return "~/pages/products/usercontrols/UCSet.ascx"
    End Function
    Public Shared Function UCType() As String
        Return "~/pages/products/usercontrols/UCType.ascx"
    End Function


    'Folders (relative to /web project)
    Public Shared Function ProductImage(p As CProduct, Optional relative As Boolean = True) As String
        Return ProductUpload(p.ProductImageOrParent, relative)
    End Function
    Public Shared Function ProductThumb(p As CProduct, Optional relative As Boolean = True) As String
        Return ProductUpload(p.ProductThumbOrParent, relative)
    End Function
    Public Shared Function ProductTiny(p As CProduct, Optional relative As Boolean = True) As String
        Return ProductUpload(p.ProductTinyOrParent, relative)
    End Function
    Public Shared Function ProductUpload(file As String, Optional relative As Boolean = True) As String
        Return String.Concat(ProductUploads(relative), file)
    End Function
    Public Shared Function ProductUploads(relative As Boolean) As String
        If relative Then Return "~/uploads/products/"
        Return String.Concat(CConfig.DropboxLiveData, ProductUploads(True).Substring(2))
    End Function
#End Region

#Region "ProductTypes"
    'List/Search
    Public Shared Function [ProductTypes]() As String
        Return "~/pages/productTypes/default.aspx"
    End Function
    Public Shared Function [ProductTypes](ByVal search As String) As String
        Return String.Concat(CSitemap.ProductTypes(), "?search=", Encode(search))
    End Function
    Public Shared Function [ProductTypes](ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.ProductTypes(String.Empty), Paging(pi))
    End Function

    'Add/Edit
    Private Shared Function ProductTypeAddEdit() As String
        Return "~/pages/productTypes/productType.aspx"
    End Function
    Public Shared Function ProductTypeAdd() As String 'May require a parentId (follow pattern below)
        Return ProductTypeAddEdit()
    End Function
    Public Shared Function ProductTypeEdit(ByVal typeId As Byte) As String
        Return String.Concat(ProductTypeAddEdit, "?typeId=", typeId)
    End Function

    'UserControls
    Public Shared Function UCProductType() As String
        Return "~/pages//productTypes/usercontrols/UCProductType.ascx"
    End Function

    'Folders (relative to /web project)
    Public Shared Function ProductTypeUploads() As String
        Return "~/uploads/productTypes/"
    End Function
#End Region

#Region "Clicks"
    'List/Search
    Public Shared Function [Clicks]() As String
        Return "~/pages/clicks/default.aspx"
    End Function
    Public Shared Function [Clicks](ByVal userName As String) As String
        Return String.Concat(CSitemap.Clicks(), "?userName=", Encode(userName))
    End Function
    Public Shared Function [Clicks](ByVal userName As String, ByVal url As String) As String
        Return String.Concat(CSitemap.Clicks(userName), "&url=", Encode(url))
    End Function
    Public Shared Function [Clicks](ByVal search As String, ByVal url As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Clicks(search, url), Paging(pi))
    End Function

    'UserControls
    Public Shared Function UCClick() As String
        Return "~/pages//clicks/usercontrols/UCClick.ascx"
    End Function
#End Region

#Region "Sessions"
    'List/Search
    Public Shared Function [Sessions]() As String
        Return "~/pages/sessions/default.aspx"
    End Function
    Public Shared Function [Sessions](ByVal search As String) As String
        Return String.Concat(CSitemap.Sessions(), "?search=", Encode(search))
    End Function
    Public Shared Function [Sessions](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Sessions(search), Paging(pi))
    End Function

    'Add/Edit
    Private Shared Function SessionAddEdit() As String
        Return "~/pages/sessions/session.aspx"
    End Function
    Public Shared Function SessionAdd() As String 'May require a parentId (follow pattern below)
        Return SessionAddEdit()
    End Function
    Public Shared Function SessionEdit(ByVal sessionId As Integer) As String
        Return String.Concat(SessionAddEdit, "?sessionId=", sessionId)
    End Function

    'UserControls
    Public Shared Function UCSession() As String
        Return "~/pages//sessions/usercontrols/UCSession.ascx"
    End Function
#End Region

#Region "Login"
    Public Shared Function Login() As String
        Return "~/admin"
    End Function
#End Region

#Region "Audit_Errors"
    'List/Search
    Public Shared Function [Audit_Errors]() As String
        Return "~/pages/audit_Errors/default.aspx"
    End Function
    Public Shared Function [Audit_Errors](ByVal search As String, ByVal uniqueOnly As Boolean) As String
        Return String.Concat(CSitemap.Audit_Errors(), "?search=", Encode(search), "&uniqueOnly=", uniqueOnly)
    End Function
    Public Shared Function [Audit_Errors](ByVal search As String, ByVal uniqueOnly As Boolean, ByVal sortBy As String, ByVal descending As Boolean, ByVal pageNumber As Integer) As String
        Return String.Concat(CSitemap.Audit_Errors(search, uniqueOnly), "&sortBy=", sortBy, "&desc=", descending, "&p=", pageNumber)
    End Function

    'USercontrols
    Public Shared Function UCError() As String
        Return "~/pages/audit_Errors/usercontrols/UCAudit_Error.ascx"
    End Function

    'View Details
    Public Shared Function [Audit_Error](ByVal errorID As Integer) As String
        Return String.Concat("~/pages/audit_Errors/audit_Error.aspx?errorID=", errorID)
    End Function
    Public Shared Function Audit_Error(ByVal type1 As Integer, ByVal message1 As Integer, ByVal type2 As Integer, ByVal message2 As Integer) As String
        Return String.Concat("~/pages/audit_Errors/audit_Error.aspx?type1=", type1, "&message1=", message1, "&type2=", type2, "&message2=", message2)
    End Function
    Public Shared Function Audit_ErrorGroup(ByVal type1 As Integer, ByVal message1 As Integer, ByVal type2 As Integer, ByVal message2 As Integer) As String
        Return String.Concat("~/pages/audit_Errors/group.aspx?type1=", type1, "&message1=", message1, "&type2=", type2, "&message2=", message2)
    End Function
    Public Shared Function Audit_ErrorGroup(ByVal type1 As Integer, ByVal message1 As Integer, ByVal type2 As Integer, ByVal message2 As Integer, ByVal sortBy As String, ByVal descending As Boolean, ByVal pageNumber As Integer) As String
        Return String.Concat(CSitemap.Audit_ErrorGroup(type1, message1, type2, message2), "&sortBy=", sortBy, "&desc=", descending, "&p=", pageNumber)
    End Function
#End Region

#Region "Roles"
    'List/Search
    Public Shared Function [Roles]() As String
        Return "~/pages/roles/default.aspx"
    End Function
    Public Shared Function [Roles](ByVal pageIndex As Integer) As String
        Return String.Concat(CSitemap.Roles, "?p=", pageIndex)
    End Function

    'Add/Edit
    Private Shared Function RoleAddEdit() As String
        Return "~/pages/roles/role.aspx"
    End Function
    Public Shared Function RoleAdd() As String 'May require a parentId (follow pattern below)
        Return RoleAddEdit()
    End Function
    Public Shared Function RoleEdit(ByVal roleName As String) As String
        Return String.Concat(RoleAddEdit, "?roleName=", roleName)
    End Function
    Public Shared Function RoleEdit(ByVal roleName As String, ByVal search As String) As String
        Return String.Concat(RoleEdit(roleName), "&search=", Encode(search))
    End Function

    'Usercontrols
    Public Shared Function UCRole() As String
        Return "~/pages/roles/usercontrols/UCRole.ascx"
    End Function


    'Folders (relative to /web project)
    Public Shared Function RoleUploads() As String
        Return "/uploads/roles/"
    End Function
#End Region

#Region "Users"
    'List/Search
    Public Shared Function [Users]() As String
        Return "~/pages/users/default.aspx"
    End Function
    Public Shared Function [Users](ByVal search As String) As String
        Return String.Concat(CSitemap.Users, "?search=", Encode(search))
    End Function
    Public Shared Function [Users](ByVal search As String, ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Users(search), Paging(pi))
    End Function

    'Usercontrols
    Public Shared Function UCUser() As String
        Return "~/pages/users/usercontrols/UCUser.ascx"
    End Function

    'Add/Edit
    Private Shared Function UserAddEdit() As String
        Return "~/pages/users/user.aspx"
    End Function
    Public Shared Function UserAdd() As String 'May require a parentId (follow pattern below)
        Return UserAddEdit()
    End Function
    Public Shared Function UserEdit(ByVal userLoginName As String) As String
        Return String.Concat(UserAddEdit, "?userLoginName=", userLoginName)
    End Function
    Public Shared Function UserEdit(ByVal roleName As String, ByVal search As String) As String
        Return String.Concat(UserEdit(roleName), "&search=", Encode(search))
    End Function

    'Folders (relative to /web project)
    Public Shared Function UserUploads() As String
        Return "/uploads/users/"
    End Function
#End Region

#Region "UserRoles"
    'List/Search
    'Public Shared Function UserRolesForUser(ByVal userLoginName As String) As String
    '    Return String.Concat("~/pages/userRoles/ForUser.aspx?userLoginName=", userLoginName)
    'End Function
    'Public Shared Function UserRolesForRole(ByVal roleName As String) As String
    '    Return String.Concat("~/pages/userRoles/ForRole.aspx?roleName=", roleName)
    'End Function
    'Public Shared Function UserRolesForUser(ByVal userLoginName As String, ByVal search As String) As String
    '    Return String.Concat(UserRolesForUser(userLoginName), "&search=", Encode(search))
    'End Function
    'Public Shared Function UserRolesForRole(ByVal roleName As String, ByVal search As String) As String
    '    Return String.Concat(UserRolesForRole(roleName), "&search=", Encode(search))
    'End Function

    'Add/Edit
    Private Shared Function UserRoleAddEdit() As String
        Return "~/pages/userRoles/userRole.aspx"
    End Function
    Public Shared Function UserRoleAdd() As String 'May require a parentId (follow pattern below)
        Return UserRoleAddEdit()
    End Function
    Public Shared Function UserRoleEdit(ByVal uRUserLogin As String, ByVal uRRoleName As String) As String
        Return String.Concat(UserRoleAddEdit, "?uRUserLogin=", uRUserLogin)
    End Function

    'UserControls
    Public Shared Function UCUserRole() As String
        Return "~/pages/userRoles/usercontrols/UCUserRole.ascx"
    End Function
#End Region



#Region "Audit Trail"
    Public Shared Function AuditTrail() As String
        Return "~/pages/audit-trail/"
    End Function
#End Region

#Region "Standard"
    'Defaults
    Public Shared Function DefaultUploadsPath() As String
        Return "~/uploads/"
    End Function

    'Utilities
    Public Shared Function Encode(ByVal s As String) As String
        If String.IsNullOrEmpty(s) Then Return String.Empty
        Return Current.Server.UrlEncode(s)
    End Function
    Public Shared Function Str(ByVal i As Integer) As String
        If Integer.MinValue = i Then Return String.Empty
        Return i.ToString
    End Function
    Public Shared Function Str(ByVal i As Guid) As String
        If Guid.Empty.Equals(i) Then Return String.Empty
        Return i.ToString
    End Function
    Public Shared Function Str(ByVal i As DateTime) As String
        If DateTime.MinValue.Equals(i) Then Return String.Empty
        Return Encode(i.ToString)
    End Function
    Public Shared Function Str(ByVal i As Boolean?) As String
        If Not i.HasValue Then Return String.Empty
        Return i.Value
    End Function
    Public Shared Function Str(ByVal i As Boolean) As String
        If Not i Then Return String.Empty
        Return i
    End Function
    Public Shared Function Str(ByVal i As Byte) As String
        If 0 = i Then Return String.Empty
        Return i.ToString
    End Function

    'Invalid ids
    Public Shared Sub RecordNotFound(ByVal entity As String)
        With HttpContext.Current.Request.QueryString
            If .Count > 0 Then RecordNotFound(entity, .Item(0)) Else RecordNotFound(entity, String.Empty)
        End With
    End Sub
    Public Shared Sub RecordNotFound(ByVal entity As String, ByVal value As Integer)
        RecordNotFound(entity, value.ToString)
    End Sub
    Public Shared Sub RecordNotFound(ByVal entity As String, ByVal pk1 As Object, ByVal pk2 As Object)
        RecordNotFound(entity, String.Concat(pk1, "/", pk2))
    End Sub
    Public Shared Sub RecordNotFound(ByVal entity As String, ByVal value As String)
        If String.IsNullOrEmpty(value) Then
            Throw New Exception(String.Concat("Invalid ", entity, "Id"))
        Else
            Throw New Exception(String.Concat("Invalid ", entity, "Id: ", value))
        End If
    End Sub


    Public Shared Function Paging(pi As CPagingInfo) As String
        Return String.Concat("&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1)
    End Function
#End Region


#Region "Mobile Device Detection"
    Public Shared Function IsMobileBrowser() As Boolean
        'GETS THE CURRENT USER CONTEXT
        Dim context As HttpContext = HttpContext.Current

        'FIRST TRY BUILT IN ASP.NT CHECK
        If context.Request.Browser.IsMobileDevice Then
            Return True
        End If
        'THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
        If context.Request.ServerVariables("HTTP_X_WAP_PROFILE") IsNot Nothing Then
            Return True
        End If
        'THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
        If context.Request.ServerVariables("HTTP_ACCEPT") IsNot Nothing AndAlso context.Request.ServerVariables("HTTP_ACCEPT").ToLower().Contains("wap") Then
            Return True
        End If
        'AND FINALLY CHECK THE HTTP_USER_AGENT 
        'HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
        If context.Request.ServerVariables("HTTP_USER_AGENT") IsNot Nothing Then
            'Create a list of all mobile types
            Dim mobiles As String() = New String() {"midp", "j2me", "avant", "docomo", "novarra", "palmos", _
   "palmsource", "240x320", "opwv", "chtml", "pda", "windows ce", _
   "mmp/", "blackberry", "mib/", "symbian", "wireless", "nokia", _
   "hand", "mobi", "phone", "cdm", "up.b", "audio", _
   "SIE-", "SEC-", "samsung", "HTC", "mot-", "mitsu", _
   "sagem", "sony", "alcatel", "lg", "eric", "vx", _
   "NEC", "philips", "mmm", "xx", "panasonic", "sharp", _
   "wap", "sch", "rover", "pocket", "benq", "java", _
   "pt", "pg", "vox", "amoi", "bird", "compal", _
   "kg", "voda", "sany", "kdd", "dbt", "sendo", _
   "sgh", "gradi", "jb", "dddi", "moto", "iphone"}

            'Loop through each item in the list created above 
            'and check if the header contains that text
            For Each s As String In mobiles
                If context.Request.ServerVariables("HTTP_USER_AGENT").ToLower().Contains(s.ToLower()) Then
                    Return True
                End If
            Next
        End If

        Return False
    End Function
#End Region
End Class
